<?php
/**
 * Created by PhpStorm.
 * User: wangjie
 * Date: 2018/11/8
 * Time: 10:33
 */
namespace api\controllers;

use Yii;
use common\services\ToolStringService;
use common\services\config\Config;

class StringController extends BaseController
{
    /**
     * 获取字符长度
     * @return array
     */
    public function actionStrLen()
    {
        $str = trim($this->request->post('str', ''));
        if (ToolStringService::mbStr($str) > 100000) return $this->errorResult(Config::$no);

        $result = ToolStringService::strLen($str);
        return $this->endReponse('0',$result);
    }

    /**
     * 字符串基础认证
     * @return array
     */
    public function actionDetectionStr()
    {
        $str = trim($this->request->post('str', ''));
        if (ToolStringService::mbStr($str) > 100000) return $this->errorResult(Config::$no);

        $result = ToolStringService::detectionStr($str);
        return $this->endReponse('0',$result);
    }

    /**
     * 字符串大小写转换
     * @return array
     */
    public function actionStrConversion()
    {
        $str = trim($this->request->post('str', ''));
        if (ToolStringService::mbStr($str) > 100000) return $this->errorResult(Config::$no);

        $result = ToolStringService::strConversion($str);
        return $this->endReponse('0',$result);
    }

    /**
     * 根据类型选择返回的字符串内容
     * !@#$%^&*
     * @return array
     */
    public function actionRandomStr()
    {
        $num = trim($this->request->post('num', ''));
        $type = trim($this->request->post('type', ''));

        $result = ToolStringService::randomStr($num, $type);
        return $this->endReponse('0',$result);
    }
}